# 树莓派GPIO控制逻辑放这里
import RPi.GPIO as GPIO
import time

# 定义继电器接的树莓派引脚
Relay_Ch1 = 26
Relay_Ch2 = 20
Relay_Ch3 = 21

# 设置GPIO模式
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(Relay_Ch1, GPIO.OUT)
GPIO.setup(Relay_Ch2, GPIO.OUT)
GPIO.setup(Relay_Ch3, GPIO.OUT)

# 根据李真需求定义的4个阀门通路
Mode = {
  'PAITAN_YIDONG': 1,
  'PAITAN_SONGDONG': 2,
  'FLOW_READ': 3,
  'PRESSURE_READ': 4
}

# 设置GPIO输出电平高低，"HIGH"为高电平，"LOW"为电平
def setOutput(io, output):
  if output == "HIGH":
    GPIO.output(io,GPIO.HIGH)
  elif output == "LOW":
    GPIO.output(io,GPIO.LOW)

# 4个阀门通路的逻辑具体实现，这里我都加了10s的等待，后面按需修改
def changeMode(mode):
  if mode == 1:#换路为排痰移动
    GPIO.output(Relay_Ch2, GPIO.LOW)
    GPIO.output(Relay_Ch3, GPIO.LOW)
    # print("Now is changing:排痰移动!")
    time.sleep(10)
  elif mode == 2:#换路为排痰松动
    GPIO.output(Relay_Ch2, GPIO.HIGH)
    GPIO.output(Relay_Ch3, GPIO.LOW)
    # print("Now is changing:排痰松动!")
    time.sleep(10)
  elif mode == 3:#换路为流量读参
    GPIO.output(Relay_Ch1, GPIO.LOW)#流量阀为完全打开状态（LOW）
    GPIO.output(Relay_Ch3, GPIO.HIGH)
    # print("Now is changing:流量读参!")
    time.sleep(10)
  elif mode == 4:#换路为压力读参
    GPIO.output(Relay_Ch1, GPIO.HIGH)#流量阀为完全闭合状态（HIGH）
    GPIO.output(Relay_Ch3, GPIO.HIGH)
    # print("Now is changing:压力读参!")
    time.sleep(10)


# 流量阀控制代码，暂无流量阀使用方式说明
def flowControl(mode):
  pass